package com.lanou3g.hw0520.view;

import com.lanou3g.hw0520.Controller.Controller;
import com.lanou3g.hw0520.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "LoginServlet",urlPatterns = "/login")
public class LoginServlet extends HttpServlet {
    private Controller controller = new Controller();

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String name = request.getParameter("username");
        String password = request.getParameter("password");

        User user = controller.loginn(name, password);
        String msg="";
        if (user==null){
            msg="denglushibai ";
            request.setAttribute("tsd",msg);
            request.getRequestDispatcher("/dasjhd.jsp").forward(request,response);

        }else {
            msg= "dengluchenggong";

            response.sendRedirect("/index.jsp");
         //   response.setHeader("Refresh","5;URL=/index.jsp");
        }



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.doPost(request,response);

    }
}
